package com.lifeonwalden.game.mindustry.entity;

import com.lifeonwalden.game.mindustry.constant.BulletType;
import com.lifeonwalden.game.mindustry.constant.League;
import com.lifeonwalden.game.mindustry.constant.SurfaceType;
import com.lifeonwalden.game.mindustry.feature.Cannon;

import java.util.Optional;

public class Player extends MovableEntity implements Cannon {
    // shoot per mini seconds
    public short shotSpeed = 100;

    public long allowedShootTime;

    public BulletType bulletType = BulletType.Stone;

    public Player() {
        this.type = SurfaceType.Player;
        this.league = League.Pathfinder;
        this.hp = this.type.maxHp;
    }

    @Override
    public Optional<Bullet> shoot(short targetX, short targetY) {
        long now = System.currentTimeMillis();
        if (now > allowedShootTime) {
            allowedShootTime = now + shotSpeed;
            return Optional.of(new Bullet(this.league, this.bulletType, this.x + 4, this.y + 4, targetX, targetY));
        }
        return Optional.empty();
    }
}
